package cc.linker.steplink.crm.merchanth5.service;


import cc.linker.steplink.crm.merchanth5.dao.ExerciseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ExerciseService {

    @Autowired
    private ExerciseDao exerciseDao;

//    public List<Map<String, Object>> getExercise(Map<String, Object> param) {
//        List<Map<String, Object>> exerciseList = exerciseDao.getExercise(param);
//        List<Map<String, Object>> resData = new ArrayList<>();
//        for(Map<String, Object> map:exerciseList){
//            Map<String, Object> tmp = new HashMap<>();
//            if("2".equals(map.get("giftType").toString())){
//                tmp.put("giftType",map.get("giftType"));
//                tmp.put("title","");
//                tmp.put("cover","");
//                tmp.put("goodsId","");
//                tmp.put("startTime",map.get("startTime"));
//                tmp.put("endTime",map.get("endTime"));
//                resData.add(tmp);
//            }else{
//                if(!StringUtils.isEmpty(map.get("giftContent"))){
//                    String[] giftContent = map.get("giftContent").toString().split(",");
//                    for(String gid:giftContent){
//                        Map<String, Object> goodsParam = new HashMap<>();
//                        goodsParam.put("goodsId",gid);
//                        Map<String, Object> goodsData = exerciseDao.getExerciseGoods(goodsParam);
//                        if(null != goodsData){
//                            tmp.put("giftType",map.get("giftType"));
//                            tmp.put("title",goodsData.get("title"));
//                            tmp.put("cover",goodsData.get("cover"));
//                            tmp.put("goodsId",gid);
//                            tmp.put("startTime",map.get("startTime"));
//                            tmp.put("endTime",map.get("endTime"));
//                            resData.add(tmp);
//                        }
//                    }
//                }
//            }
//        }
//        return resData;
//    }

    public List<Map<String, Object>> getExerciseByOrder(Map<String, Object> param) {
        String[] split;
        if(!StringUtils.isEmpty(param.get("orderId"))){
            split = param.get("orderId").toString().split(",");
        }else{
            split = param.get("orderSn").toString().split(",");
        }
        return exerciseDao.getExerciseRecord(split);
    }

    public List<Map<String, Object>> getExerciseByGoods(Map<String, Object> param) {
        String[] split = param.get("goodsId").toString().split(",");
        return exerciseDao.getExerciseByGoods(split);
    }
}
